<template>
  <div>
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span>全部删除</span> &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true"></van-icon>
    </van-cell>

    <van-cell v-for="(item, index) in searchHistory" :key="index" @click="deleteSingle(index, item)" :title="item">
      <van-icon
        name="close"
        v-show="isDeleteShow"
      ></van-icon>
    </van-cell>
  </div>
</template>

<script>
export default {
  props: {
    searchHistory: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      isDeleteShow: false
    }
  },
  methods: {
    // 删除单个
    deleteSingle (index, item) {
      if (this.isDeleteShow) {
        return this.searchHistory.splice(index, 1)
      }
      this.$emit('search', item)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
